#include"stack.h"

void STackTest()
{
	STdatetype tmp;
	ST s;
	STinit(&s);
	STpush(&s, 1);
	STpush(&s, 2);
	while (!STempty(&s))
	{
		tmp = STtop(&s);
		printf("%d ", tmp);
		STpop(&s);
	}
	STpush(&s, 3);
	STpush(&s, 4);
	STpush(&s, 5);
	while (!STempty(&s))
	{
		tmp = STtop(&s);
		printf("%d ", tmp);
		STpop(&s);
	}
	STdestroy(&s);
	return;
}

bool judge(ST* ps, STdatetype x)
{
	if (x == ')' && (STtop(ps) == '(') ||
		x == ']' && (STtop(ps) == '[') ||
		x == '}' && (STtop(ps) == '{'))
		return true;
	return false;
}

bool isValid(char* s)
{
	ST stack;
	STinit(&stack);
	while (*s)
	{
		if (*s == '(' || *s == '[' || *s == '{')
		{
			STpush(&stack, *s);
		}
		else
		{
			if (STempty(&stack))
				return false;
			if (judge(&stack, *s))
			{
				STpop(&stack);
			}
			else
				return false;
		}
		++s;
	}
	STdestroy(&s);
	return true;
}
void STackTest2()
{
	char s[10] = "()";
	isValid(s);
}

int main()
{
	STackTest();
	STackTest2();
	return 0;
}